/*
 * Created by JFormDesigner on Sat Aug 16 15:29:10 CST 2025
 */

package org.xl.main.url;

import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.util.URLUtil;

import java.awt.*;
import java.awt.event.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import javax.swing.*;

/**
 * @author Windows
 */
public class UrlEncoderFrameFrame extends JFrame {
    public UrlEncoderFrameFrame() {
        initComponents();
    }

    private void urlbmBtomOk(ActionEvent e){
        // TODO add your code here
        try {
            String text = textArea1.getText();
            textArea2.setText(URLUtil.encode(text));
        } catch (UtilException ex) {
            textArea2.setText("编码出错");
        }
    }

    private void urlJmBtnOk(ActionEvent e){
        // TODO add your code here
        try {
            String text = textArea1.getText();
            textArea2.setText(URLUtil.decode(text));
        } catch (UtilException ex) {
            textArea2.setText("解码出错");
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        scrollPane1 = new JScrollPane();
        textArea1 = new JTextArea();
        label1 = new JLabel();
        textArea2 = new JTextArea();
        button1 = new JButton();
        button2 = new JButton();
        label2 = new JLabel();

        //======== this ========
        setTitle("URL\u7f16\u89e3\u7801");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(textArea1);
        }
        contentPane.add(scrollPane1);
        scrollPane1.setBounds(105, 5, 1600, 175);

        //---- label1 ----
        label1.setText("\u539f\u59cburl:");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(45, 55), label1.getPreferredSize()));
        contentPane.add(textArea2);
        textArea2.setBounds(110, 220, 1800, 600);

        //---- button1 ----
        button1.setText("url\u7f16\u7801");
        button1.addActionListener(e -> urlbmBtomOk(e));
        contentPane.add(button1);
        button1.setBounds(335, 185, 100, button1.getPreferredSize().height);

        //---- button2 ----
        button2.setText("url\u89e3\u7801");
        button2.addActionListener(e -> urlJmBtnOk(e));
        contentPane.add(button2);
        button2.setBounds(510, 185, 74, 25);

        //---- label2 ----
        label2.setText("\u7ed3\u679c\u96c6:");
        contentPane.add(label2);
        label2.setBounds(50, 280, 42, 17);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JScrollPane scrollPane1;
    private JTextArea textArea1;
    private JLabel label1;
    private JTextArea textArea2;
    private JButton button1;
    private JButton button2;
    private JLabel label2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
